<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once(dirname(__FILE__) . "/../common/Common.php");
require_once(dirname(__FILE__) . "/../dbcom/AppointCom.php");
require_once(dirname(__FILE__) . "/../dbcom/UserCom.php");

$appointcom = new AppointCom();
$common = new Common();
$usercom = new UserCom();

$userid = $common->getLogin();
if (!isset($userid) || empty($userid)) {
    //返回
    echo json_encode(array("code" => 100, "msg" => "cannot get userid"));
    exit();
}

$user = $usercom->getUserById($userid);
//var_dump($user);
//初始化返回json的数组原型
$result = array("code" => 0, "data" => "", "num" => 0,"date"=>"");
$time = time();
$date = date("Y-m-d H:i:s",$time);
if ($user['role'] == 0) {
    $resnum = $appointcom->getCountByTime($time);
    $result['num'] = $resnum;
    $result['date'] = $date;
    echo json_encode($result);
} else {
    $rolearr = explode(",", $user['role']);
    if (!in_array("4", $rolearr)) {
        echo json_encode(array("code" => 100, "msg" => "user hasnot power"));
        exit();
    }
    $number = $appointcom->getwCountByTime($user['community_id'], $time);
    $result['num'] = $number;
    $result['date'] = $date;
    echo json_encode($result);
}
exit();
